import {mergeOptions} from "./utils.js";

export function initGlobalApi(Vue) {
    // 添加一个静态方法 mixin
    Vue.options = {
        _base:Vue
    }
    Vue.mixin = function (mixin) {
        this.options = mergeOptions(this.options, mixin)
        return this
    }

    Vue.extend = function (options){
        function Sub(options = {}){
            this._init(options)
        }
        Sub.prototype = Object.create(Vue.prototype)
        Sub.prototype.constructor = Sub
        Sub.options = mergeOptions(Vue.options,options)
        return Sub
    }

    Vue.options.components = {}
    Vue.component = function (id,options){
        options = typeof options === "function" ? options : Vue.extend(options)
        Vue.options.components[id] = options
    }
}